﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example11.aspx.cs" Inherits="Chapter28.Example11" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 28-11 复制元素</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style>
        table {
            border: solid thin black;
            border-collapse: collapse;
            margin: 10px;
        }

        td {
            padding: 4px 5px;
        }
    </style>
</head>
<body>
    <table border="1">
        <thead>
            <tr>
                <th>Multiply</th>
                <th>Reult</th>
            </tr>
        </thead>
        <tbody id="fruitsBody">
            <tr>
                <td class="sum">1 * 1</td>
                <td class="result">1</td>
            </tr>
        </tbody>
    </table>

    <button id="add">Add Row</button>

    <script>
        var talbeBody = document.getElementById("fruitsBody");

        document.getElementById("add").onclick = function () {
            var count = talbeBody.getElementsByTagName("tr").length + 1;
            var newElem = talbeBody.getElementsByTagName("tr")[0].cloneNode(true);
            newElem.getElementsByClassName("sum")[0].firstChild.data = count + " * " + count;
            newElem.getElementsByClassName("result")[0].firstChild.data = count * count;
            talbeBody.appendChild(newElem);
        };
    </script>
</body>
</html>
